/**
 * 
 */
package ac.svn.accesscontrol.manager;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

import ac.notification.event.NotificationEvent;
import ac.notification.manager.NotificationRegistrar;
import ac.svn.accesscontrol.controller.TagProcessor;
import ac.svn.accesscontrol.controller.UIController;
import ac.svn.accesscontrol.store.Dictionary;
import ac.svn.accesscontrol.store.ISVNIdentifier;
import ac.svn.accesscontrol.ui.MainWindow;

/**
 * @author Enigmanic
 *
 */
public class InitManager {
	MainWindow mainWindow;
	TagProcessor tagProcessor;
	UIController uiController;
	public InitManager()
	{
		mainWindow = new MainWindow();
		mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		tagProcessor = new TagProcessor();
		uiController = new UIController();
	
		chooseFile();
		mainWindow.setVisible(true);
		
	}
	private void chooseFile() {
		
		JFileChooser fileChooser = new JFileChooser("D:\\");
		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		String fileName = "";
		int selectedOption = fileChooser.showOpenDialog(mainWindow);
		if(JFileChooser.CANCEL_OPTION != selectedOption)
		{
			fileName = fileChooser.getSelectedFile().getAbsolutePath();
		}
		else
		{
			JOptionPane.showMessageDialog(mainWindow, "No File selected!","Invalid Selection!",JOptionPane.ERROR_MESSAGE);
			System.exit(0);
		}
		
		if(fileName.isEmpty())
		{
			JOptionPane.showMessageDialog(mainWindow, "No File selected!","Invalid Selection!",JOptionPane.ERROR_MESSAGE);
			System.exit(0);
		}
		Dictionary.setCurrentAccessFile(fileName);
		NotificationEvent event = new NotificationEvent(ISVNIdentifier.CMD_PROCESS_FILE);
		event.setPropertyValue(fileName);
		NotificationRegistrar.dispatchNotification(event)	;
		
	}
	public static void main(String args[]) throws Exception
	{
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		InitManager manager = new InitManager();
	}

}
